<template>
    <el-card shadow="never" class="border-0">
        <!-- 新增和刷新 -->
        <div class="flex items-center justify-between mb-4">
            <el-button type="success">新增</el-button>

            <el-tooltip effect="dark" content="刷新数据" placement="bottom">
                <el-button type="success" text @click="getData()">
                    <el-icon>
                        <Refresh />
                    </el-icon>
                </el-button>
            </el-tooltip>
        </div>
        <!-- 表格 -->
        <el-table :data="tableData" stripe style="width: 100%" v-loading="loading">
            <el-table-column prop="title" label="标题" min-width="100" />
            <el-table-column prop="create_time" label="创建时间" min-width="180" />
            <el-table-column label="操作" width="180" align="center">
                <template #default="scope">
                    <el-button size="small" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
                    <el-popconfirm title="确认删除该公告?" confirm-button-text="确认" cancel-button-text="取消"
                        @confirm="handleDelete(scope.$index, scope.row)">
                        <template #reference>
                            <el-button size="small" type="danger">删除</el-button>
                        </template>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="flex items-center justify-center mt-5">
            <el-pagination small background layout="prev,pager,next" :total="total" :current-page="currentPage"
                    :page-size="limit" @current-change="getData" />
        </div>
    </el-card>


    <!-- 新增弹框 -->
    <FormDrawer ref="formDrawerRef">内容</FormDrawer>
</template>
<script setup>
import { ref } from 'vue'
import FormDrawer from '~/components/FormDrawer.vue'
import { getNotice } from '~/api/notice.js'

const formDrawerRef=ref(null)
//加载loading
const loading = ref(false)
const tableData = ref([])
const activeId = ref(0) //选中的图库

//分页
const currentPage = ref(1)
const total = ref(0)
const limit = ref(10)

getData()
// 获取数据
function getData(p=null) {
    if (typeof p == 'number') {
        currentPage.value = p
    }

    loading.value = true
    getNotice(currentPage.value).then(res => {
        tableData.value = res.list
        total.value = res.totalCount

       
    }).finally(() => {
        loading.value = false
    })
}

//修改
const handleEdit = (a, b) => {
    formDrawerRef.value.open()
}
//删除
const handhandleDeleteleEdit = (a, b) => {

}
</script>

<style scoped>

</style>